<template>
  <div id="b" style="width: 800px;height: 500px"/>
</template>

<script>
import { onMounted } from "vue";
import * as echarts from 'echarts';
import axios from "axios";

export default {

  // eslint-disable-next-line vue/multi-word-component-names
  name: "B",

  setup() {

    let xydate;

    onMounted(() => {
      axios.get("/api/b").then((res) => {

        xydate = res.data
        setData()

        console.log(xydate)


        let myChart = echarts.init(document.getElementById("b"));

        // 绘制图表
        myChart.setOption({
          title: {
            text: '第一季度各地区的消费总额占比',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: '消费总额',
              type: 'pie',
              radius: '50%',
              data: xydate,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        });
      })
    });

    function setData() {
      xydate = xydate.map(v => {
        return {
          value: v.totalconsumption,
          name: v.regionname
        }
      })
    }
  }
}
</script>

<style scoped>

</style>